package com.sean.findme;

import com.sean.findme.dbentrys.FmCommDBEntry;
import com.sean.findme.dbentrys.ShopDetailDBEntry;
import com.sean.findme.dbentrys.SubwayDBEntry;
import com.sean.findme.dbentrys.SubwayDetailDBEntry;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;



public class FmDBHelp extends SQLiteOpenHelper {

	private SQLiteDatabase db;
	private final static String FmDbName = "Fm.db";
	private static FmDBHelp instance;
	
	public FmCommDBEntry commDBEntry = null;
	public SubwayDBEntry subwayDBEntry = null;
	public ShopDetailDBEntry shopDetailDBEntry = null;
	public SubwayDetailDBEntry subwayDetailDBEntry = null;
	
	public FmDBHelp(Context context, int version) {
		super(context, FmDbName, null, version);
		this.db = this.getWritableDatabase();
		
		instance = this;
		
		commDBEntry = new FmCommDBEntry(context);
		subwayDBEntry = new SubwayDBEntry(context);
		shopDetailDBEntry = new ShopDetailDBEntry(context);
		subwayDetailDBEntry = new SubwayDetailDBEntry(context);
	}


	public SQLiteDatabase GetFmDB() {
		this.db = this.getWritableDatabase();
		return db;
	}

	public void CloseFmDB() {

		db.close();
	}

	public static FmDBHelp getInstance(Context context, int version) {

		if(instance == null) {
			instance = new FmDBHelp(context, 1);
		}

		return instance;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		FmCommDBEntry.createTables(db);
		ShopDetailDBEntry.createTable(db);
		SubwayDBEntry.createTable(db);
		SubwayDetailDBEntry.createTable(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

}
